$(document).ready(function() {

          var mod;// modal itself
          var modOpen;//modal open Button
          var modClose;//modal close Button

          var modalInit = function (modalID) {

                var mod = (modalID); //pass ID to function
                var modOpen = (mod + 'BttnOpen'); // generate the Open button ID
                var modClose = (mod + 'BttnClose'); // generate the Close button ID
                
                $(mod).easyModal({ // general settings
                  top: 100,
                  autoOpen: false,
                  overlayOpacity: 0.3,
                  overlayColor: "#333",
                  overlayClose: true,
                  closeOnEscape: true
                });
                $(modOpen).click(function(e){ //click on OPenButton ID to open
                    $(mod).trigger('openModal'); //open method from Plugin
                    e.preventDefault();
                });
                $(modClose).click(function(e){  //click on OPenButton ID to close
                    $(mod).trigger('closeModal'); //clsoe method from Plugin
                    e.preventDefault();
                });

          }
          //find all MODAL IDs in the container with the ID modals
            
          var modalIDs;

          var modalIDsFx = function(){

              modalIDs = [];// Array for ModalIDs
              $("#modals").find(".modal").each(function(){ 
                modalIDs.push('#' + this.id); //collects Ids and push's them in to the array
              });
              //console.log(modalIDs); //debug
              var i;
              var l = (modalIDs.length - 1);  
              for( i=0; i <= l; i++){
                 modalInit(modalIDs[i]);// for every collected ID call function with collected ID as parameter
              } 
           }
          modalIDsFx();// call function to start passing IDs to modalInit
          
           
});
          
       